define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/index',
                    del_url: 'user/del',
                    table: 'c_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                mobileResponsive: false, //是否自适应移动端
                columns: [
                    [
                     	{field: 'head', title: __('头像'),formatter:Table.api.formatter.image, operate: false},
                        {field: 'uid', title: __('Uid')},
                        {field: 'nickname', title: __('Nickname'), operate: false},
                        {field: 'ucount', title: __('大赢家'), operate: false},
                        {field: 'honorscore', title: __('Honorscore'), operate: false},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
                        {field: 'roomcount', title: __('游戏场次'), operate: false},
                        {field: 'winsum', title: __('游戏局数'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, formatter: function (value, row, index) {
                        	if(row.uid == row.owner){
                        		return '<a title="加分" class="btn btn-xs btn-info btn-dialog" href="/club/user/add/ids/'+row.id+'"> 赠送荣誉分</a>&nbsp;&nbsp;'
                        		+'<a class="btn btn-xs btn-primary" href="/club/honorscorelog/index/clubid/'+row.clubid+'/uid/'+row.uid+'">荣誉分赠送记录</a>&nbsp;&nbsp;';
                        	}else{
	                        	return '<a title="加分" class="btn btn-xs btn-info btn-dialog" href="/club/user/add/ids/'+row.id+'"> 赠送荣誉分</a>&nbsp;&nbsp;'
	                        	+'<a class="btn btn-xs btn-primary" href="/club/honorscorelog/index/clubid/'+row.clubid+'/uid/'+row.uid+'">荣誉分赠送记录</a>&nbsp;&nbsp;'
	                        	+'<a class="btn btn-xs btn-danger btn-delone" href="javascript:;">删除</a>';
                        	}
						},events: Table.api.events.operate}
                    ]
                ],
                onLoadSuccess: function (data) {
                	//显示人数
					$("#top_club").html('人数：'+ data.total + '/500 &nbsp;&nbsp;&nbsp; 荣誉分：'+data.totalscore);
					
					//成员记录
					$("#user_log").click(function(){
						window.location.href="/club/userlog/index/clubid/"+data.clubid;
					});
					
					//成员申请
					$("#user_apply").click(function(){
						window.location.href="/club/userapply/index/clubid/"+data.clubid;
					});
					
					//添加成员
					$("#game_user").click(function(){
						window.location.href="/club/gameuser/index/clubid/"+data.clubid;
					});
					
					//游戏账变
					$("#room_score").click(function(){
						window.location.href="/club/annalscore/index/clubid/"+data.clubid;
					});
	            }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});


